﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UtilLib.Misc;

namespace UnitTest.Misc
{
	[TestClass]
	public class UnitTest1
	{
		[TestMethod, TestCategory("Misc")]
		public void TestBitOperation()
		{
			var read = 1;
			var write = 2;
			var delete = 4;

			var flag = read | write;
			Assert.IsTrue(BitOperation.HasFlag(flag, read));
			Assert.IsFalse(BitOperation.HasFlag(flag, delete));

			BitOperation.SetFlag(ref flag, delete);
			Assert.IsTrue(BitOperation.HasFlag(flag, delete));

			BitOperation.ResetFlag(ref flag, delete);
			Assert.IsFalse(BitOperation.HasFlag(flag, delete));
		}

		[TestMethod, TestCategory("Misc")]
		public void TestPropertyCopy()
		{
			Class1 obj = new Class1();
			PropertyCopy.CopyProperties(new { A = "a", C = "c" }, obj);
			Assert.AreEqual(obj.A, "a");
		}

		class Class1
		{
			public string A { get; set; }
			public string B { get; set; }
		}
	}
}
